﻿using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ST.Torch.WebApi.Core.Manager
{

    public interface ICacheManage
    {
        #nullable enable
         /// <summary>
                /// 
                /// </summary>
                /// <typeparam name="T"></typeparam>
                /// <param name="key"></param>
                /// <returns></returns>
         public T? Get<T>(string key);
         public Task<T?> GetAsync<T>(string key);
        #nullable disable
        /// <summary>
        /// 获取缓存项没有就设置
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">键</param>
        /// <param name="factory">设置缓存对象</param>
        /// <returns>缓存对象</returns>
        public T GetOrCreate<T>(string key, Func<ICacheEntry, T> factory);

        public Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> factory);



       
        /// <summary>
        /// 设置缓存项
        /// </summary>
        /// <typeparam name="T">缓存对象类型</typeparam>
        /// <param name="key">键</param>
        /// <param name="t">缓存对象</param>
        /// <param name="second">过期时间-秒</param>
        /// <param name="IsSlidingExpiration">是否滑动过期</param>
        /// <returns></returns>
        public bool Set<T>(string key, T t, long second = 0, bool IsSlidingExpiration = true);
        public Task<bool> SetAsync<T>(string key, T t, long second = 0, bool IsSlidingExpiration = true);

        /// <summary>
        /// 移除一个缓存项
        /// </summary>
        /// <param name="key">缓存项key</param>
        /// <returns>true成功,false失败</returns>
        public bool Remove(string key);
        public Task<bool> RemoveAsync(string key);
    }

}
